package com.stu.service.service.impl;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.UUID;

import jedis.JedisUtil;
import jedis.ObjectUtil;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.stu.entity.service.News;
import com.stu.service.base.impl.BaseService;
import com.stu.service.service.INewsService;
import com.stu.utils.NewsUtils;

@Service
public class NewsService extends BaseService<News> implements INewsService{

	@Transactional
	@Override
	public boolean updateNews() throws SQLException, IOException {
		try {
			List<News> newsList=null;
			newsList = NewsUtils.getNews();
			//清除以前的缓存数据
			jedisUtils.getJedis().expire("news".getBytes(), 0);
//			jedisUtils.getJedis().del("news".getBytes());
			for(int i=0;newsList!=null&&i<newsList.size();i++){
					News n=newsList.get(i);
					n.setUuid(UUID.randomUUID().toString().replaceAll("-", ""));
					baseDao.save(n);
					jedisUtils.zadd("news", System.currentTimeMillis(), n);
//					JedisUtil.lpush("news".getBytes(), ObjectUtil.objectToBytes(n));
			}
//			jedis.set("news".getBytes(), listTranscoder.serialize(newsList))
			return true;
		} catch (Exception e) {
			
		}
		return false;
	}

}
